﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SAI
{
    class IterativeDeepening
    {
        private Graph _graph;
        private Node _goal;
        private int _numOfRepeatedNodes;

        public IterativeDeepening(Graph graph, Node goal)
        {
            _graph = graph;
            _goal = goal;
        }

        public List<Node> compute()
        {
            List<Node> path = new List<Node>();
            int depth = 0;
            bool foundGoal = false;
            do
            {
                Node node = DLS(_graph.START, depth);
                //if(node != null)

            } while (!foundGoal);
            return path;
        }

        private Node DLS(Node node, int depth)
        {
            if (depth == 0 && _goal == node)
                return node;
            else if (depth > 0)
            {
                foreach (Edge neighbor in node.NEIGHBORS)
                    if (neighbor.TO.VISITED == true)
                        return DLS(neighbor.TO, depth - 1);
            }
            else
                return null;

            return null;
        }
    }
}
